package com.ruoyi.orderManagement.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 取消订单的队列配置
 */
@Configuration
@Slf4j
public class RabbitCancelOrderConfig {
    //普通订单队列，指定死信交换机和路由键
    @Bean
    public Queue orderQueue2() {
        return QueueBuilder.durable("order.queue2")  //订单队列
                .deadLetterExchange("order.dlx.exchange2")  //设置死信交换机
                .deadLetterRoutingKey("order.key.dlx2")      //设置死信路由键
                .ttl(5 * 60 * 1000)   //默认是40分钟 (开发阶段1分钟)
                .maxLength(30000)   //最大长度
                .build();
    }
    //普通交换机
    @Bean
    public DirectExchange orderExchange2() {
        return new DirectExchange("order.exchange2");
    }
    //普通订单队列绑定普通交换机
    @Bean
    public Binding orderBinding(Queue orderQueue2, DirectExchange orderExchange2) {
        return BindingBuilder.bind(orderQueue2).to(orderExchange2).with("order.key.normal2");
    }
    //死信队列
    @Bean
    public Queue orderDlxQueue2() {
        return new Queue("order.dlx.queue2");
    }
    //死信交换机
    @Bean
    public DirectExchange orderDlxExchange2() {
        return new DirectExchange("order.dlx.exchange2");
    }
    //死信队列绑定死信交换机
    @Bean
    public Binding orderDlxBinding(Queue orderDlxQueue2, DirectExchange orderDlxExchange2) {
        return BindingBuilder.bind(orderDlxQueue2).to(orderDlxExchange2).with("order.key.dlx2");
    }
}
